<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/7/23
 * Time: 16:11
 */
namespace app\admin\controller;
use think\Request;
use think\Db;
class Agreement extends \app\admin\controller\Base
{
    protected $res = array(
        'index' => array('css' => '2,3,4' , 'js' => 'list') ,
        'edit' => array('css' => '2,3,4,5,9,select-css', 'js' => 'ueditor_config,ueditor_all,ueditor_lang,select-js'),
    );

    /**
     * index 首页数据
     * @return mixed
     */
    public function index(){
        $list = Db::table('up_about_us')
            ->field('a_id,a_register_agreement')
            ->select();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $this->assign ([
            'list'=>$list,
            'action'=>$action,
        ]);
        return $this->fetch();
    }

    /**
     * 修改
     * @return mixed
     */
    public function edit(){
        $id = input('id');
        if(request()->isAjax ()){
            extract(input());
            if($n_content == ''){
                return $this->api_error('注册协议不能为空', '14001');
            }
            $param = [
                'a_register_agreement'=>$n_content,
                'a_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_about_us')->where('a_id',$aid)->update($param);
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $list = Db::table('up_about_us')
            ->where('a_id',$id)
            ->value('a_register_agreement');
        $this->assign ('id',$id);
        $this->assign ('data',$list);
        return $this->fetch('edit');
    }
}